<template>
  <span v-if="buttonIcon" class="svg-view" :style="getStyle">
    <span v-if="isExternal" role="img" class="anticon app-iconify"
    ><embed style="width: 1em; height: 1em" :src="buttonIcon"
    /></span>
    <component v-else :is="buttonIcon" />
  </span>
</template>

<script>
import { defineComponent, computed } from 'vue';
export default defineComponent({
  name: 'SvgView',
  props: {
    buttonIcon: {
      type: String,
      default: '',
    },
    size: {
      type: [Number, String],
      default: 16,
    },
    color: {
      type: [String],
    },
  },
  setup(props) {
    // 判断图标类型
    const isExternal = computed(() => {
      return /^(https?:|mailto:|tel:)/.test(props.buttonIcon);
    });
    const getStyle = computed(() => {
      const { size, color } = props;
      let s = `${size}`;
      s = `${s.replace('px', '')}px`;
      return {
        fontSize: s,
        color,
      };
    });
    return {
      isExternal,
      getStyle,
    };
  },
});
</script>
<style lang="less" scoped>
.svg-view {
  line-height: 0;
}
</style>
